package leetcode.editor.offer;

// 剑指 Offer 15. 二进制中1的个数
// https://leetcode.cn/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/
class ErJinZhiZhong1deGeShuLcof {
    public static void main(String[] args) {
        Solution solution = new ErJinZhiZhong1deGeShuLcof().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int count = 0;
            while (n != 0) {
                if ((n & 1) == 1) count++;
                // 无符号位右移
                n >>>= 1;
            }
            return count;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
